<?php
class subscriptionsModel extends BaseModel implements Model {
    function __construct() {
        parent::__construct("subscriptions", "ticket");
        $this->addField("email", Model::TYPE_VARCHAR);
        $this->addField("ticket", Model::TYPE_VARCHAR, Model::MOD_PRIMARY);
        $this->addField("active", Model::TYPE_INT);
    }

    public function renderAlias($record) {
        $result = $record;
        return $result;
    }

    public function evaluate($ticket) {
        $result = false;
        $query = "UPDATE subscriptions SET active=1 WHERE ticket='$ticket'";
        Database::executeQuery($query);
        if (mysql_affected_rows() > 0) { $result = true; }
        return $result;
    }

    public function removeEmail($ticket) {
        $query = "DELETE FROM subscriptions WHERE ticket='$ticket'";
        Database::executeQuery($query);
    }

    public function isAuthorized($operation, $subject = "") {
        return true;
//        if (Auth::isAdmin()) { return true; }
/*
        switch ($operation) {
            case "update" :
            case "delete" :
            case "addnew" : {
                if (Auth::canChangeDrivers()) { return true; }
            }
            case "list" : {
                if (Auth::canListDrivers()) { return true; }
            }
        }
        return false;
*/
    }

    public function modifyDatabaseInput($data) {
        $rseult = array();
        foreach ($data as $key=>$value) {
            if ($key == "random") { continue; }
            else if ($key == "captcha") { continue; }
            $result[$key] = $value;
        }
        return $result;
    }
}

?>
